# @Time : 2020/8/26 15:24
# @Author : Fioman 
# @Phone : 13149920693
"""
split 和 merge  拆分和合并通道
"""
import cv2 as cv
import numpy as np

image = cv.imread("pic/10.png")
newWidth = 500
newHeight = int(image.shape[0] / image.shape[1] * newWidth)
image = cv.resize(image, (newWidth, newHeight), interpolation=cv.INTER_AREA)
B, G, R = cv.split(image)
print(image.shape, B.shape, G.shape, R.shape)
M = np.zeros(image.shape[:2], dtype=np.uint8)
cv.imshow("B", B)
cv.imshow("G", G)
cv.imshow("R", R)
cv.waitKey(0)

Bcolor = cv.merge([B, M, M])
Gcolor = cv.merge([M, G, M])
Rcolor = cv.merge([M, M, R])
cv.imshow("Bcolor", Bcolor)
cv.imshow("Gcolor", Gcolor)
cv.imshow("Rcolor", Rcolor)
cv.waitKey(0)

image = cv.imread("pic/10.png")
B, G, R = cv.split(image)
print("value = {}".format(R[94, 180]))
print("B value = {}".format(B[78, 13]))
print("G value = {}".format(G[5, 80]))

M1 = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
M2 = np.array([[202, 119, 154], [106, 119, 11], [186, 48, 250]])
res = np.sum(np.multiply(M1,M2))
print(res)

M2 = np.ones((3,3))*1/9
M3 = np.array([[18,143,222],[233,179,97],[234,142,149]])
res = np.sum(np.multiply(M2,M3))
print(res)



















